package com.mask.sca.gateway.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.client.WebClient;

import reactor.core.publisher.Mono;

@RestController
public class SwaggerV2CompatController {
    private final WebClient webClient = WebClient.create();

    @GetMapping("/v2/api-docs")
    public Mono<ResponseEntity<String>> v2ToV3(@RequestParam(required = false) String group) {
        // 默认分组名处理，可根据实际情况调整
        String v3Url = "/v3/api-docs";
        if (group != null && !group.isEmpty() && !"default".equals(group)) {
            v3Url += "/" + group;
        }
        return webClient.get()
                .uri(v3Url)
                .retrieve()
                .toEntity(String.class);
    }
} 